#include "voltage_detection.h"
#include "zf_driver_adc.h"
#define FILTER_NUM  (50)
#define BATTERY ADC1_CH3_A11
#define SERVO0 ADC0_CH0_A0
#define SERVO1 ADC0_CH1_A1
#define SERVO2 ADC0_CH2_A2
#define SERVO3 ADC0_CH3_A3
#define BATTERY_RATIO (108.557/12.9*12.6)
#define SERVO0_RATIO (108.557)
#define SERVO1_RATIO (108.557)
#define SERVO2_RATIO (108.557)
#define SERVO3_RATIO (108.557)


struct voltage_s voltage;

void voltageDetectionInit(void)
{
    adc_init(BATTERY,ADC_12BIT);
    adc_init(SERVO0,ADC_12BIT);
    adc_init(SERVO1,ADC_12BIT);
    adc_init(SERVO2,ADC_12BIT);
    adc_init(SERVO3,ADC_12BIT);
    voltage.battery = 12.0f;
    voltage.servo0 = 8.0f;
    voltage.servo1 = 8.0f;
    voltage.servo2 = 8.0f;
    voltage.servo3 = 8.0f;

}

void voltageGet(void)
{
    voltage.battery = (float)adc_mean_filter_convert(BATTERY,FILTER_NUM)/BATTERY_RATIO;
    voltage.servo0 = (float)adc_mean_filter_convert(SERVO0,FILTER_NUM)/SERVO0_RATIO;
    voltage.servo1 = (float)adc_mean_filter_convert(SERVO1,FILTER_NUM)/SERVO1_RATIO;
    voltage.servo2 = (float)adc_mean_filter_convert(SERVO2,FILTER_NUM)/SERVO2_RATIO;
    voltage.servo3 = (float)adc_mean_filter_convert(SERVO3,FILTER_NUM)/SERVO3_RATIO;
}
